package test.threadTest;

public class Ticket {
    public static void main(String[] args) {
        MyTicket ticket = new MyTicket();
        for (int i = 0; i < 20; i++) {
            new Thread(ticket).start();
        }
    }
}
class MyTicket implements Runnable{
    int count = 10;
    @Override
    public void run() {
        synchronized (this){
            if (count > 0){
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+":"+count--);
            }
            else
                return;
        }
    }
}
